package com.bw.doctor.service.impl;
/**
 * @Author：尚志豪
 * @Package：com.bw.doctor.service.impl
 * @Project：doudi-group2-shixun-02
 * @name：PharmacyHistoricalPrescriptionServiceImpl
 * @Date：2025/2/25 20:32
 */

import com.bw.common.core.domain.R;
import com.bw.doctor.domain.ElectronicPrescribing;
import com.bw.doctor.domain.res.PrescriptionParameterRes;
import com.bw.doctor.mapper.PharmacyHistoricalPrescriptionMapper;
import com.bw.doctor.service.PharmacyHistoricalPrescriptionService;
import com.bw.domain.PatientInformation;
import com.bw.domain.Prescription;
import com.bw.domain.res.HistoricalPrescriptionRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: doudi-group2-shixun-02
 * @description: 我的药房历史处方
 * @author: CuiFu Bo
 * @create: 2025-02-25 20:32
 **/
@Service
public class PharmacyHistoricalPrescriptionServiceImpl implements PharmacyHistoricalPrescriptionService
{
    @Autowired
    private PharmacyHistoricalPrescriptionMapper prescriptionMapper;
    /**
     * B端 我的药房 历史处方列表
     */
    @Override
    public List<com.bw.domain.res.HistoricalPrescriptionRes> listOfHistoricalPrescriptions(Long doctorId) {
        return prescriptionMapper.listOfHistoricalPrescriptions(doctorId);
    }
    /**
     * B端 我的药房 历史处方详情
     */
    @Override
    public HistoricalPrescriptionRes historicalPrescriptionDetails(Long id) {
        com.bw.domain.res.HistoricalPrescriptionRes prescriptionRes = prescriptionMapper.historicalPrescriptionDetails(id);
        System.out.println("prescriptionRes" + prescriptionRes);
        List<String> strings = new ArrayList<>();
        for (String s : prescriptionRes.getDrugNames().split(",")) {
            strings.add(s);
        }
        System.out.println("s" + strings);
        prescriptionRes.setDrugName(strings);
        System.out.println("完整的:===" + prescriptionRes);
        return prescriptionRes;
    }
    /**
     * B端 我的药房 开处方
     */
    @Override
    @Transactional
    public R makeAPrescriptionAdd(PrescriptionParameterRes parameterRes) {
        // 历史处方添加
        prescriptionMapper.makeAPrescriptionAdd(parameterRes);
        System.out.println("添加后返回的主键id=====" + parameterRes.getId());
        // 中间表添加
        prescriptionMapper.SRestorativesPmpmrAdd(parameterRes.getRestorativesIds(),parameterRes.getId());
        // new一个新对象
        ElectronicPrescribing electronicPrescribing = new ElectronicPrescribing();
        // 赋值id
        electronicPrescribing.setId(parameterRes.getId());
        // 赋值病症名称
        electronicPrescribing.setDiagnosis(parameterRes.getDiagnosis());
        // 赋值药品名称
        electronicPrescribing.setDrugName(parameterRes.getDrugNames());
        System.out.println("电子处方: " + electronicPrescribing);
        return R.ok(electronicPrescribing);
    }
    /**
     * B端 我的药房 通过医生查看病症
     */
    @Override
    public List<Prescription> seeYourDoctorForSymptoms(Long doctorId) {
        return prescriptionMapper.seeYourDoctorForSymptoms(doctorId);
    }
    /**
     * B端 我的药房 通过id查询患者信息
     */
    @Override
    public PatientInformation queryPatientInformationById(Long patientInformationId) {
        return prescriptionMapper.queryPatientInformationById(patientInformationId);
    }
}

